﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using KZ.Exception;
using KZ.Lottery.BLL;
using KZ.Lottery.Entities;
using KZ.Lottery.Resources;

namespace KZ.Lottery
{
    public partial class FrmSchedule : Form
    {
        #region Private Methods

        private void FrmSchedule_Load(object sender, EventArgs e)
        {
            LoadSchedule();
        }

        private void LoadSchedule()
        {
            try
            {
                List<Schedule> scheduleList = ScheduleBLL.GetScheduleList();
                int count = scheduleList.GroupBy(s => s.No).Count();

                List<Schedule> tempList;
                int tempCount;
                ListViewItem item;
                for (int i = 0; i < count; i++)
                {
                    tempList = new List<Schedule>(scheduleList.Where(s => s.No == scheduleList[0].No));
                    scheduleList.RemoveAll(s => s.No == tempList[0].No);

                    item = new ListViewItem(KZ_Resource.ResourceManager.GetString(tempList[0].No));
                    item.BackColor = i % 2 == 0 ? lsvSchedule.BackColor : Color.Azure;
                    item.SubItems.Add(tempList.Single(s => s.Type == KZ_Resource.ChannelType_Main).ChannelName);

                    tempList.RemoveAll(s => s.Type == KZ_Resource.ChannelType_Main);

                    tempCount = tempList.Count;
                    for (int j = 0; j < tempCount; j++)
                    {
                        item.SubItems.Add(tempList[j].ChannelName);
                    }

                    lsvSchedule.Items.Add(item);
                }
            }
            catch (DataAccessException ex)
            {
                Global.SetMessage(lblMessage, ex.Message, false);
            }
            catch (System.Exception ex)
            {
                Log.LogEx("LoadSchedule", ex);
                Global.SetMessage(lblMessage, KZ_Message.BLM_ERR_GENERAL, false);
            }
        }

        #endregion Private Methods

        #region Constructors

        public FrmSchedule()
        {
            InitializeComponent();
        }

        #endregion Constructors
    }
}